<!--{template /module/admin/view/head}-->
<div id="left_layout">
	<div id="main_content" class="container-fluid">
		<!--{template /module/admin/view/head_nav}-->
		<div class="row-fluid">
			<form method="post" action="{$ADMIN_SCRIPT}/bbs/forum/{$dispatches[method]}&id={$_var[gp_id]}&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}" onsubmit="javascript:return check_form(this);">
				<input type="hidden" name="formsubmit" value="yes" />
				<input type="hidden" name="hdnFile01" value=""/>
				
				<div class="well widget">
					<div class="widget-header">
						<p class="text">* {lang admin.validate.require}</p>
					</div>
					<div class="widget-content">
						<fieldset>
							<label>{lang bbs.forum_edit.view.no.label}</label>
							<input type="text" class="input-mini" name="txtDisplayOrder" placeholder="{lang bbs.forum_edit.view.no.placeholder}..." maxlength="3" value="{$forum[DISPLAYORDER]}" /> 
							<span class="help-inline">{lang bbs.forum_edit.view.no.tips}</span>
							
							<label>{lang bbs.forum_edit.view.name.label} *</label>
							<input type="text" class="input-xlarge" name="txtName" placeholder="{lang bbs.forum_edit.view.name.placeholder}..." maxlength="50" value="{$forum[NAME]}" /> 
							<span class="help-inline">{lang bbs.forum_edit.view.name.tips}</span>
							
							<label>{lang bbs.forum_edit.view.manager.label}</label>
							<input type="text" class="input-xlarge"  name="txtManager" placeholder="{lang bbs.forum_edit.view.manager.placeholder}..." maxlength="50" value="{$forum[MANAGER]}" /> 
							<span class="help-inline">{lang bbs.forum_edit.view.manager.tips}</span>
							
							<hr/>
							<label>{lang bbs.forum_edit.view.remark.label}</label>
							<textarea class="span6" rows="2" cols="45" name="txtRemark">{$forum[REMARK]}</textarea>
							<span class="help-inline">{lang bbs.forum_edit.view.remark.tips}</span>
							
							<label>{lang bbs.forum_edit.view.rule.label}</label>
							<textarea class="span6" rows="6" cols="45" name="txtRule">{$forum[RULE]}</textarea>
							<span class="help-inline">{lang bbs.forum_edit.view.rule.tips}</span>
							
			                
							<!--{if count($groups) > 0}-->
								<hr/>
								<label>{lang bbs.forum_edit.view.group.label}</label>
								<!--{loop $groups $key $group}-->
								<label class="checkbox inline">
				                <input type="checkbox" name="cbxGroup[]" class="fancy" value="{$key}" {if $forum['GROUPS'][$key]}checked="checked"{/if} /> {$group[CNAME]}
								</label>
				                <!--{/loop}-->
			                <!--{/if}-->
			                
							<hr/>
							<label>{lang bbs.forum_edit.view.issubscribe.label}</label>
							<label class="checkbox inline">
								<input type="radio" name="rdoIsSubscribe" class="fancy" value="1"  {if $forum['ISSUBSCRIBE'] == 1}checked="checked"{/if} /> {lang bbs.forum_edit.view.issubscribe.enabled}
							</label>
							<label class="checkbox inline">
                				<input type="radio" name="rdoIsSubscribe" class="fancy" value="0" {if $forum['ISSUBSCRIBE'] == 0}checked="checked"{/if} /> {lang bbs.forum_edit.view.issubscribe.disabled}
							</label>
			                
							<hr/>
							
							<label>{lang bbs.forum_edit.view.audit.label}</label>
							<label class="checkbox inline">
								<input type="radio" name="rdoIsAudit" class="fancy" value="1"  {if $forum['ISAUDIT'] == 1}checked="checked"{/if} /> {lang bbs.forum_edit.view.audit.enabled}
							</label>
							<label class="checkbox inline">
                				<input type="radio" name="rdoIsAudit" class="fancy" value="0" {if $forum['ISAUDIT'] == 0}checked="checked"{/if} /> {lang bbs.forum_edit.view.audit.disabled}
							</label>
							
							<hr/>
							<div id="div_guest">
						        <label>{lang bbs.forum_edit.view.guest.label}</label>
						        <label class="checkbox inline">
				                	<input type="radio" name="rdoGuest" class="fancy" value="0" {if $forum['GUEST'] == 0}checked="checked"{/if}/> {lang bbs.forum_edit.view.guest.disabled}
				                </label>
				                <label class="checkbox inline">
				                	<input type="radio" name="rdoGuest" class="fancy" value="1" {if $forum['GUEST'] == 1}checked="checked"{/if}/> {lang bbs.forum_edit.view.guest.enabled}
				                </label>
			                </div>
			                
			                <div id="div_users" {if $forum['GUEST'] == 0}style="display:none;"{/if}>
			                	<hr/>
								<label>{lang bbs.forum_edit.view.guest.users.label}</label>
								
								<div class="form-inline">
									<input type="text" name="txtUserName" id="txt_user_name" maxlength="30" class="input-medium" />
									<input type="button" class="btn" name="btnCheckUser" id="btn_check_user" value="{lang bbs.forum_edit.view.guest.users.button.add}" />
									<span class="help-inline">{lang bbs.forum_edit.view.guest.users.tips}</span>
								</div>
								
								<table>
									<tr>
										<td>
											<table class="table" style="margin-top:30px;">
												<tbody id="tbody_user">
												<!--{loop $forum_users $loop $user}-->
												<!--{template /module/bbs/view/forum_user}-->
												<!--{/loop}-->
												</tbody>
											</table>
										</td>
									</tr>
								</table>
							</div>
							
							<hr/>
						    <label>{lang bbs.forum_edit.view.file01.label}</label>
						    <table class="swfupload">
								<tr>
									<td width="160" valign="top" align="center">
										<p class="img" id="p_file01">
											<!--{if is_array($forum['FILE01'])}-->
											<img src="{$forum[FILE01][0]}" data="{$forum[FILE01][4]}" width="160" style="width:160px;" border="0"/>
											<!--{else}-->
											<img src="static/images/no-picture.jpg" data="" width="160" style="width:160px;" />
											<!--{/if}-->
										</p>
										<hr/>
										<div class="upload-button"><span id="swfu_file01"></span></div>
									</td>
								</tr>
						    </table>
						</fieldset>
						
						<hr/>
						
						<fieldset>
							<!--{if $dispatches['method'] == '_add'}-->
							<button type="submit" class="btn btn-small btn-primary" {$dispatches[operations][add]}>{lang admin.operation.submit}</button>
							<!--{else}-->
							<button type="submit" class="btn btn-small btn-primary" {$dispatches[operations][edit]}>{lang admin.operation.submit}</button>
							<!--{/if}-->
							<button type="reset" class="btn btn-small">{lang admin.operation.reset}</button>
							<button type="button" class="btn btn-small" onclick="javascript:location.href='{$ADMIN_SCRIPT}/bbs/forum&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}';">{lang admin.operation.go.back}</button>
						</fieldset>
					</div>
				</div>	
			</form>
		</div>
	</div>
</div>

<script type="text/javascript" src="static/plugins/swfupload.js"></script>
<script type="text/javascript" src="static/plugins/swfupload_handlers.js"></script>
<script type="text/javascript" src="static/plugins/swfupload_images.js"></script>

<script>
var swfu_file01 = null;

swfupload_params.limit = 1;
swfupload_params.uploaded = 0;

function fileQueueError(file, errorCode, message) {
	if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
		$.dialog({message:'{lang admin.validate.swfupload.lang.limit}'});
	}else{
		$.dialog({message:'{lang admin.validate.swfupload.echo.fail}'});
	}
}

function uploadSuccess(file, serverData) {
	if(serverData.substring(0, 7) === "FILEID:") {
		var tempArr = serverData.split('|');
		var photoPath = formatFilePath(serverData.substring(7));
		
		$('#p_' + tempArr[5] + ' img').attr('src', photoPath).attr('data', serverData.substring(7));
	}else $.dialog({message:serverData});
}

function createSwfUpload(file, title){
	var swf_config = {
		upload_url: "{$ADMIN_SCRIPT}/bbs/forum/_upload&file=" + file + "&_SALT={$_var[current][SALT]}",
		
		file_size_limit : "400KB", 
		file_types : "*.jpg;*.bmp;*.gif;*.png",
		file_types_description : "JPG Images",
		file_upload_limit : "0",
		
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
		
		button_image_url : "static/images/swfupload/swfupload.png",
		button_placeholder_id : "swfu_" + file,
		button_width: 150,
		button_height: 18,
		button_text : '{lang admin.validate.swfupload.lang.button.choice}' + title + '({lang admin.validate.swfupload.lang.button.limit}400K)',
		button_text_style : '',
		button_text_top_padding: 0,
		button_text_left_padding: 18,
		
		flash_url : "static/swfupload.swf", 
		debug: false
	};
	
	return new SWFUpload(swf_config);
}

function check_form(frm){
	if(frm.txtName.value.trim().length == 0){
		$(frm.txtName).next('.help-inline').css('color', 'red');
		frm.txtName.focus();
		return false;
	}
	
	frm.hdnFile01.value = $('#p_file01 img').attr('data') ? $('#p_file01 img').attr('data') : '';
	
	return true;
}

function delete_user(userid){
 	$("#tbody_user input[rel='" + userid + "']").parent().parent().remove();
 	$('#txt_user_name').val('');
}

$(function(){
	$('.fancy').uniform();
	
	$('fieldset input,textarea,select').blur(function(){
		$(this).next('.help-inline').css('color', '#333');
	});
	
	$('#div_guest :radio').click(function(){
		if($(this).val() == '1') $('#div_users').show();
		else $('#div_users').hide();
	});
	
	$('#txt_user_name').keypress(function(evt){
		if(evt.keyCode == 13){
			evt.preventDefault();
			$('#btn_check_user').click();
		}
	});
	
	$('#btn_check_user').click(function(){
		$('#tbody_user #error').remove();
		var username = $('#txt_user_name').val();
		
		if(username == ''){
			$('#tbody_user').prepend('<tr id=\"error\"><td colspan=\"3\"><font color=red>{lang bbs.forum_edit.view.guest.users.tips}</font></td></tr>');
			$('#txt_user_name').focus();
			return false;
		}
		
		$.get('{$ADMIN_SCRIPT}/bbs/forum/_user', {username: username}, function(data){
			if(data.indexOf('id="error"') != -1) $('#tbody_user').prepend(data);
			else {
				var userid = $(data).find("input[name='txtUserID[]']").val();
				if($("#tbody_user input[rel='" + userid + "']").length > 0){
					$('#tbody_user').prepend('<tr id=\"error\"><td colspan=\"3\"><font color=red>{lang bbs.forum_edit.validate.guest.users.limit}</font></td></tr>');
				}else $('#tbody_user').append(data);
			}
			
			$('#txt_user_name').val('').focus();
		});
	});
	
	$('.swfupload img').dblclick(function(){
		$(this).attr({src:'static/images/no-picture.jpg', data:''});
	});
	
	swfu_file01 = createSwfUpload('file01', '{lang bbs.forum_edit.view.file01}');
});
</script>
<!--{template /module/admin/view/foot}-->